package com.inspur.mr.electric;

import java.io.IOException;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class ElectricReducer extends Reducer<Text, ElectricWritable, ElectricWritable, NullWritable> {
@Override
protected void reduce(Text key, Iterable<ElectricWritable> values,Context context)
		throws IOException, InterruptedException {
        double cf = 0;
        double xyf = 0;
        double kt = 0;
        double sum = 0;
        for(ElectricWritable e : values) {
        	cf +=e.getCf();
        	xyf += e.getXyf();
        	kt += e.getKt();
        }
        sum = cf+xyf+kt;
        ElectricWritable ele = new ElectricWritable(key.toString(), cf, xyf, kt, sum);
        context.write(ele,NullWritable.get());
}	

}